package main;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;

import part2.*;

public class Test2 {
	public static void main(String[] args) {
		OrderedLinkedList<Integer> il = OrderedLinkedList.newInstance();
		for (int i = 4; i < 7; i += 2)
			il.add(i);
		for (int i = 5; i < 8; i += 2)
			assert il.add(i);
		for (int i = 0; i < 4; i++)
			assert il.add(i);
		for (int i = 8; i < 10; i++)
			assert il.add(i);
		for (int i = 0; i < 10; i++)
			assert !(il.add(i));
		assert il.toString().equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
		assert il.contains(0) && il.contains(5) && il.contains(9);
		assert !(il.contains(-1) || il.contains(10));
		for (int i = 0; i < 10; i++)
			assert il.contains(i);
		OrderedLinkedList<Integer> il2 = OrderedLinkedList.newInstance(il.iterator());
		assert il.equals(il);
		assert il.equals(il2);
		assert il2.equals(il);
		assert il.compareTo(il) == 0;
		assert il.compareTo(il2) == 0;
		assert il2.compareTo(il) == 0;
		assert !il.remove(-1);
		assert !il.remove(10);
		assert il.toString().equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
		assert il.remove(0);
		assert il.compareTo(il2) > 0;
		assert il2.compareTo(il) < 0;
		assert il2.remove(0);
		assert il.remove(9);
		assert il.compareTo(il2) < 0;
		assert il2.compareTo(il) > 0;
		assert il2.remove(9);
		assert il.remove(5);
		assert il.toString().equals("[1, 2, 3, 4, 6, 7, 8]");
		assert il.size() == 7;
		assert il.compareTo(il2) > 0;
		assert il2.compareTo(il) < 0;
		il = OrderedLinkedList.newInstance(Arrays.asList(0, 2, 3, 4, 5, 6, 8).iterator());
		il2 = OrderedLinkedList.newInstance(Arrays.asList(1, 3, 4, 5, 7, 9).iterator());
		il.merge(il2);
		assert il.toString().equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]");
		assert il.max().equals(9);
		il.reverse();
		assert il.toString().equals("[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]");
		il.merge(il);
		assert il.toString().equals("[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]");
		il.add(-1);
		assert il.toString().equals("[9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1]");
		OrderedList<Integer> il3 = new OrderedLinkedList<>(ListUtil.reverseOrder(ListUtil.<Integer> naturalOrder()),
				Arrays.asList(10, 11, 12, -2).iterator());
		assert il3.toString().equals("[12, 11, 10, -2]");
		il.merge(il3);
		assert il.toString().equals(
				"[12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2]");
		il.reverse();
		assert il.toString().equals(
				"[-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]");
		il = OrderedLinkedList.newInstance();
		il.merge(il2);
		assert il.toString().equals("[1, 3, 4, 5, 7, 9]");
		il.merge(OrderedLinkedList.<Integer> newInstance());
		assert il.toString().equals("[1, 3, 4, 5, 7, 9]");
		il = OrderedLinkedList.newInstance();
		il.reverse();
		assert il.toString().equals("[]");
		il.add(1);
		il.reverse();
		assert il.toString().equals("[1]");
		il.add(2);
		assert il.toString().equals("[1, 2]");
        il.reverse();
		assert il.toString().equals("[2, 1]");
		OrderedList<Calendar> cl1 = OrderedLinkedList.newInstance(
				Arrays.<Calendar> asList(new GregorianCalendar(2007, 1, 27), new GregorianCalendar(2004, 7, 20)).iterator());
		OrderedList<GregorianCalendar> cl2 = null;
		assert !cl1.equals(cl2);
		cl2 = OrderedLinkedList.newInstance(
				Arrays.<GregorianCalendar> asList(new GregorianCalendar(2001, 8, 21), new GregorianCalendar(1972, 10, 17)).iterator());
		assert cl1.compareTo(cl1) == 0;
		assert cl2.compareTo(cl2) == 0;
		assert cl1.compareTo(cl2) > 0;
		// assert cl2.compareTo(cl1) < 0;    
		
		
		System.out.println("TESTS PASSED!");
	}
}
